import { pathExists } from 'fs-extra';
import { homedir } from 'os';
import { join } from 'path';

import c from '../colors';
import type { Config } from '../definitions';
import { fatal } from '../errors';
import { logger } from '../log';
import type { Plugin, PluginType } from '../plugin';

export async function checkOhosPackage(config: Config): Promise<string | null> {
  // 检查鸿蒙包配置
  logger.info(`Checking HarmonyOS package configuration...`);
}

export async function editProjectSettingsOhos(config: Config): Promise<void> {
  // 编辑鸿蒙项目设置
  logger.info(`Configuring HarmonyOS project settings...`);
}

export async function checkDevEcoStudio(): Promise<string | null> {
  // 动态检查 DevEco Studio 是否安装
  const username = process.env.USERNAME || process.env.USER || 'user';
  const commonPaths = [
    // 标准安装路径
    'C:\\Program Files\\Huawei\\DevEco Studio',
    'D:\\Program Files\\Huawei\\DevEco Studio',
    // 用户目录安装路径
    join(homedir(), 'AppData', 'Local', 'Huawei', 'DevEco Studio'),
    `C:\\Users\\${username}\\AppData\\Local\\Huawei\\DevEco Studio`,
    // 自定义安装路径
    'C:\\DevEco Studio',
    'D:\\DevEco Studio',
    join(homedir(), 'DevEco Studio'),
    // 华为开发者工具目录
    'C:\\Huawei\\DevEco Studio',
    'D:\\Huawei\\DevEco Studio',
  ];

  for (const path of commonPaths) {
    if (await pathExists(path)) {
      return path;
    }
  }

  return null;
}

export async function getOhosStudioPath(): Promise<string> {
  // ... existing code ...
}

export function resolvePlugin(plugin: Plugin): void {
  // ... existing code ...
}